package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.OrderSetting;
import com.itheima.pojo.OrderSettingVo;
import com.itheima.pojo.Setmeal;
import com.itheima.service.OrderService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FilenameFilter;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/ordersetting")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    /*修改预约人数*/
    @PostMapping("/editNumberByOrderDate")
    public Result editNumberByOrderDate(@RequestBody OrderSetting orderSetting) throws ParseException {
        log.info("新增检查项：{}", orderSetting);
        orderService.editNumberByOrderDate(orderSetting);
        return new Result(true,MessageConstant.ORDERSETTING_SUCCESS,null);
    }
    /*根据id查询套餐*/
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(@DateTimeFormat(pattern="yyyy-MM")Date month) throws ParseException {
        List<OrderSettingVo> orderSettings=orderService.getOrderSettingByMonth(month);
        return new Result(true,MessageConstant.GET_ORDERSETTING_SUCCESS,orderSettings);
    }
    /*模板下载*/
    @GetMapping("/download")
    public String download(String filename) throws Exception {
        orderService.download(filename);
        return "文件下载";
    }
    /*文件上传*/
    @PostMapping("/upload")
    public Result upload(MultipartFile excelFile) throws Exception{
        orderService.upload(excelFile);
        return new Result(true,MessageConstant.ORDERSETTING_SUCCESS,null);
    }
}
